<!-- 
  HTML DOM 元素对象：

  getAttribute 得到属性值
  setAttribute 设置属性值
  
 -->
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>11</title>
</head>

<body>

  <p id="intro">我的课程</p> 
  <ul> 
    <li title="JS">JavaScript</li> 
    <li title="JQ">JQuery</li> 
    <li title="">HTML/CSS</li> 
    <li title="JAVA">JAVA</li> 
    <li title="">PHP</li> 
  </ul>
  <h1>以下为li列表title的值,当title为空时，新设置值为"WEB前端技术":</h1>


  <script>
    var Lists = document.getElementsByTagName("li");
    for (var i = 0; i < Lists.length; i++) {
      var text = Lists[i].getAttribute("title");
      console.log(text);
      document.write(text + "<br>");
      if (text == "") {
        Lists[i].setAttribute("title", "WEB前端技术");
        document.write(Lists[i].getAttribute("title") + "<br>");
      }
    }

  </script>

</body>

</html>